<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        p.top {
            height: 36px;
            line-height: 36px;
        }

        #btn {
            border: 0;
            font-size: 24px;
            width: 100px;
            height: 36px;
            line-height: 36px;
            border-radius: 5px;
            background-color: rgb(17, 185, 236);
            color: snow;
            vertical-align: middle;
            outline: none;
            cursor: pointer;
        }

        input {
            border: 2px solid #666;
            height: 30px;
            vertical-align: middle;
            outline: 0;
            font-size: 14px;
            padding-left: 18px;
            width: 300px;
            margin-right: 50px;
            border-radius: 36px;
        }
    </style>
</head>

<body>
    <p class="top">活动主题：<input type="text" id="title"> <button id="btn">提交</button></p>
    <div id="blogContent"></div>
    <img src="" id="img" alt="">
    <script src="./jquery-3.5.1/jquery-3.5.1.min.js"></script>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/wangeditor@latest/dist/wangEditor.min.js"></script>
    <script type="text/javascript">
        const E = window.wangEditor;
        const editor = new E(document.getElementById('blogContent'));
        editor.config.uploadImgServer = '/upload';
        editor.config.height = 500; // 设置富文本框的高度
        editor.config.uploadImgAccept = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', "svg"]
        editor.config.uploadImgMaxLength = 2;   // 一次最多2张
        editor.config.uploadFileName = 'img'

        editor.config.uploadImgHooks = {
            customInsert: function (insertImgFn, result) {
                insertImgFn(result.data)
            }
        }
        editor.create();
        $("#btn").click(function () {
            // console.log($("#blogContent img").eq(0).attr("src"));
            // $("#img").attr("src", $("#blogContent img").eq(0).attr("src"))

            const time = new Date;
            $.post("/addBlog", {
                title: $("#title").val(),
                publishTime: time.toLocaleDateString() + " " + time.toLocaleTimeString().slice(2),
                abstract: $("#blogContent p").eq(0).text(),
                content: editor.txt.html(),
                bgUrl: $("#blogContent img").eq(0).attr("src")
            }, success => {
                console.log(success);
            })

        })

    </script>
</body>

</html>